package com.liycode.controller;

import com.liycode.service.UserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

@Controller
public class TestController {

    private static final Logger logger = LogManager.getLogger("test");

    @Resource
    private UserService userService;

    @RequestMapping(value = "/greeting/{name}", method = RequestMethod.GET)
    public String greeting(@PathVariable(value = "name") String name
            , Model model) {

        Long userId = userService.selectByLoginName(name);

        model.addAttribute("name", name);
        model.addAttribute("uid", userId);

        logger.info(name + ":" + userId);
        return "greeting";
    }
}
